home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / mslang / comtst / comtest.c next >
Encoding:
C/C++ Source or Header  |  1993-09-26  |  896 b   |  41 lines

  1. /******************************************************************************
  2.  Example of Using COM Ports with standard C funtions.
  3.  
  4.  by: Karl Weller
  5.  [74620,2112]
  6. ******************************************************************************/
  7. #include "stdio.h"
  8. #include "time.h"
  9.  
  10. main()
  11. {
  12.     FILE *fp;
  13.     int i;
  14.     char comport[10];
  15.     long t1,t2;
  16.     
  17.     printf("\Which COM PORT (1-4) ");
  18.     i=getch();
  19.     
  20.     if (i<'0' || i>'4') exit(0);
  21.     sprintf(comport,"COM%c",i);
  22.     
  23.     fp = fopen(comport,"w");
  24.  
  25.     printf("\nAnswering %s\n",comport);
  26.     fprintf(fp,"ATA\n");
  27.     fflush(fp);
  28.     
  29.     printf("WAIT 6 SECONDS\n");
  30.     time(&t1);
  31.     do {
  32.         time(&t2);
  33.     } while(t1+6L>t2);
  34.  
  35.     printf("HANGUP %s\n",comport);
  36.     fprintf(fp,"ATH\n");
  37.     fflush(fp);
  38.  
  39.     fclose(fp);
  40. }
  41.